//package com.github.llyb120.calengine.parser;
//
//import cn.hutool.core.io.FileUtil;
//import cn.hutool.poi.excel.ExcelUtil;
//import cn.hutool.poi.excel.ExcelWriter;
//import com.alibaba.fastjson.JSONObject;
//import com.github.llyb120.calengine.rule.RuleEngine;
//import com.github.llyb120.performance.define.Field;
//import com.github.llyb120.performance.define.Scope;
//import lombok.Cleanup;
//import org.beetl.sql.core.SQLManager;
//import org.beetl.sql.core.SQLReady;
//
//import java.io.File;
//import java.util.*;
//
//import static com.github.llyb120.calengine.rule.RuleEngine.SCOPE;
//
//public class ScopeParser extends AbstractParser {
//
//    @Override
//    public void parse(String[] args) throws Exception {
//
//    }
//
//
//    public void generate(String scopeName, String target){
//        RuleEngine ruleEngine = new RuleEngine();
//        Scope scope = ruleEngine.getRule(SCOPE, scopeName);
//        if (scope == null) {
//            return;
//        }
//        SQLManager sqlManager = DatasourceParser.getSqlManager(ruleEngine, scope.getUse());
//        List<JSONObject> result = sqlManager.execute(new SQLReady(scope.getSql()), JSONObject.class);
//        //group
//        File dir = new File(target);
//        dir.mkdirs();
//        Map<String, List> ret = new LinkedHashMap<>();
//        for (JSONObject item : result) {
//            StringJoiner sj = new StringJoiner("-");
//            for (String s : scope.getGroup()) {
//                sj.add(item.getString(s));
//            }
//            String key = sj.toString();
//            List entries = ret.get(key);
//            if (entries == null) {
//                entries = new ArrayList();
//                ret.put(key, entries);
//            }
//            entries.add(item);
//        }
//        ret.entrySet().parallelStream()
//                        .forEach(e -> {
//                            @Cleanup ExcelWriter writer = ExcelUtil.getWriter(dir.getAbsolutePath() + "/" + e.getKey() + ".xlsx");
//                            writer.write(e.getValue(), true);
//                            writer.flush();
//                        });
//    }
//
//}
